********************************************************************************
*REPLICATION MATERIAL FOR Rudolph, L., T. D�ubler (2016) "Holding Individual Representatives Accountable: The Role of Electoral Systems", The Journal of Politics, forthcoming.
********************************************************************************

********************************************************************************
*This Do-File replicates the results presented in Tables 3 and 4 of the main text and in Tables A4, A7, A8, A11, A12, A13 of the Online Appendix (OLPR-Level)
********************************************************************************

version 13
set more off
clear all

/* install estout-package by Ben Jann in Version st0085_2 (Stata Journal 14-2) via "findit st0085_2".
		st0085_2 from http://www.stata-journal.com/software/sj14-2
		SJ14-2 st0085_2. Update: Making regression... / Update: Making regression
		tables from stored / estimates / by Ben Jann, University of Bern */

/* install cem package by M. Blackwell, S. Iacus, G. King, and G. Porro
SJ-9-4  st0176  . . . . . . . . . . . . cem: Coarsened exact matching in Stata
        . . . . . . . . . . . .  M. Blackwell, S. Iacus, G. King, and G. Porro
        Q4/09   SJ 9(4):524--546                                 (no commands)
        introduces coarsened exact matching, a new method for
        improving the estimation of causal effects by reducing
        imbalance in covariates between treated and control groups*/



*set working directory to folder containing replication data files main folder 

cd ""

capture log close
log using tables\replication_OLPR.log, replace

*********************************************
* Table 3: Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Regression Solution
*********************************************


use tables\candidates_csu_replication.dta, clear
keep if year==2013

global listdum = "list_f list_s list_t" 
global list = "list_pre listN_cand"
global role = "gov2 frontrunner bezirksvorsitz01 parteiamt local_committee"
global demo = "title cand_age gender" 
global comp = "i.leg incumb_2000 nachruecker incumbency_stk  district_candidate" 

eststo clear

quietly eststo :  reg sv_cand affair $listdum , r
quietly eststo :  reg sv_cand affair $listdum $list $role $demo $comp i.rbez, r
quietly eststo :  reg sv_cand affair_cont $listdum , r
quietly eststo :  reg sv_cand affair_cont $listdum $list $role $demo $comp i.rbez, r

esttab, compress b(2) se(2) star(* 0.05) label order(*affair*)  /// 
rename(affair_cont affair) /// 
indicate("Controls for list and candidate quality and OLPR district = $list $role title gender cand_age *leg* incumb_2000  nachruecker incumbency_stk  district_candidate *rbez*") ///
title({\b Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Regression Solution}) ///
note("Note: Regression with robust standard errors on 2013 second vote shares of CSU candidates within their respective party list. Treatment indicator with binary (Models 1-3) or continuous specification (Models 4-6). Controls (used where indicated) include dummies for first, second and third list position, absolute list position, length of list, dummies for candidates being member of local interest committee, cabinet member, regional party leader, leading party functionary, CSU frontrunner, district incumbent, being district candidate, having academic titles, being female, being incumbent since 2000, the number of legislative periods, age in years as well as dummies for the seven OLPR ballots (electoral districts) of Bavaria.") ///
mtitles("binary treat." "binary treat." "cont. treat." "cont. treat.") ///
collabels("Cand. second vote share" ,lhs(Dep. var.: Within CSU list vote))



*********************************************
*Table 4: Impact of Affair on Vote Shares of Candidates within CSU Party Lists - CEM Matching Solution 
*********************************************

use tables\candidates_csu_replication.dta, clear
keep if year==2013

eststo clear

**
*Model 1: matching on controls as specified below, comp. to regression esp. not OLPR list length, local interest comitee, incumbent since 2000 

cem list_pre(1.5 2.5 3.5 6.5 10.5) gov2 frontrunner bezirksvorsitz01 parteiamt title cand_age(20 30 45 60 80) gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
eststo c: reg sv_cand affair list_pre gov2 frontrunner bezirksvorsitz01 parteiamt title cand_age gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 [iweight=cem_weights]

*add scalar for pre-matching imbalance
quietly imb list_pre gov2 frontrunner bezirksvorsitz01 parteiamt title cand_age gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): c
*add scalar for post-matching imbalance
quietly cem list_pre(1.5 2.5 3.5 6.5 10.5) gov2 frontrunner bezirksvorsitz01 parteiamt title cand_age(20 30 45 60 80) gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar cemL1 = r(L1): c
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': c
estadd scalar controls = `a0': c
*add scalar for control-group mean
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): c

**
*Model 2: matching on fewer controls, esp. not OLPR list length, local interest comitee, incumbent since 2000 & for district candidate, frontrunner, local party leader, party functionary,  list position coarsening reduced to (1 2 3-10 else)

cem list_pre(1.5 2.5 10.5) gov2 title cand_age(20 30 45 60 80) gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
eststo e: reg sv_cand affair list_pre gov2 title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 [iweight=cem_weights]

*add scalar for pre-matching imbalance
quietly imb list_pre gov2 title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): e
*add scalar for post-matching imbalance
quietly cem list_pre(1.5 2.5 10.5) gov2 title cand_age(20 30 45 60 80) gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar cemL1 = r(L1): e
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': e
estadd scalar controls = `a0': e
*add scalar for control-group mean
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): e

**
*Model 3: matching on fewer controls (comp Mod. 3, add. list position coarsening reduced to (1 2 else))

cem list_pre(1.5 2.5) gov2 title gender cand_age(20 30 45 60 80) rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7  , treatment(affair)
eststo g: reg sv_cand affair list_pre title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 [iweight=cem_weights]

*add scalar for pre-matching imbalance
quietly imb list_pre gov2 title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): g
*add scalar for post-matching imbalance
quietly cem list_pre(1.5 2.5) gov2 title gender cand_age(20 30 45 60 80) rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7  , treatment(affair)
estadd scalar cemL1 = r(L1): g
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': g
estadd scalar controls = `a0': g
*add scalar for control-group mean
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): g

**
*Model 4: matching only on pre-electoral list position, coarsened to 1 2 3-6 7-10 else)

cem list_pre(1.5 2.5 3.5 6.5 10.5)  , treatment(affair)

eststo i: reg sv_cand affair list_f list_s list_t list_pre  [iweight=cem_weights]

*add scalar for pre-matching imbalance
quietly imb list_pre gov2  , treatment(affair)
estadd scalar imbL1 = r(L1): i
*add scalar for post-matching imbalance
quietly cem list_pre(1.5 2.5 3.5 6.5 10.5) , treatment(affair)
estadd scalar cemL1 = r(L1): i
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': i
estadd scalar controls = `a0': i
*add scalar for control-group mean
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): i

**
*Table

esttab c e g i, compress label b(2) se(2) star(* 0.05) stats(N treat controls imbL1 cemL1 control_mean, fmt(a3 a3) labels(N "Matched treated" "Matched controls" "Pre-Matching L1 Imbalance" "Post-Matching L1 Imbalance")) ///
order(*affair*) keep(affair   _cons) indicate("Matching variables included as controls = list_?  *rbez*" ) /// cand_age *gov2 list_pre
title({\b Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - CEM Matching Solution}) ///
note("Note: Average treatment effect on the treated for second vote shares within CSU regional lists for running affair candidates with weights obtained by coarsened exact matching (standard errors in parentheses). Control variables adjust for remaining imbalance (L1 statistic) in the sample and improve efficiency. For Model 1, candidates are matched by ballot position (coarsened to 1, 2, 3, 4-6, 7-10, else), dummies for government function, being frontrunner, regional party leader, party functionary, academic title, gender, being SMD candidate, dummies for the seven regional ballots and age (coarsened to 20-29, 30-44, 45-59, 60-80). For Model 2, candidates are matched by ballot position (coarsened to 1, 2, 3-10, else), dummies for government function, title, gender, regional ballot dummies and age (coarsened to 20-29, 30-44, 45-59, 60-80). Model 3 differs from Model 2 by coarsening ballot position broader, only by 1, 2, else. Model 4 only matches by ballot position (coarsened to 1, 2, 3, 4-6, 7-10, else).") ///
collabels("binary treat.",lhs(Dep. var.: CSU vote shares))



*********************************************
*Table A4: 2013 Summary Statistics for Candidate Level Controls
*********************************************

eststo clear
estpost ttest list_f list_s list_t list_pre listN_cand gov2 frontrunner bezirksvorsitz01 parteiamt local_committee title cand_age gender leg incumb_2000 district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7, by(affair)

esttab , label compress star(* 0.05 ) /// 
cells("mu_1(fmt(%12.2f) label(Control)) mu_2(fmt(%12.2f) label(Treated)) b(fmt(%12.2f) star label(Diff-In-2013-Means))" "mean mean se(par fmt(2))" ". . .") ///
title({\b Table : 2013 Summary Statistics for Candidate Level Controls}) ///
note("Note: Comparison of 2013 control variables (mean and mean difference with standard errors in parentheses) for all running affair list candidates.")



*********************************************
*Table A7: Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Regression Solution - Display of All Coefficients of Table 3 and Additional Models
*********************************************

use tables\candidates_csu_replication.dta, clear
keep if year==2013

global listdum = "list_f list_s list_t" 

global list = "list_pre listN_cand"
global role = "gov2 frontrunner bezirksvorsitz01 parteiamt local_committee"
global demo = "title cand_age gender" 
global comp = "i.leg incumb_2000 nachruecker incumbency_stk  district_candidate" 

eststo clear

quietly eststo a:  reg sv_cand affair $listdum , r
quietly eststo b:  reg sv_cand affair $listdum $list $role $demo $comp , r
quietly eststo c:  reg sv_cand affair $listdum $list $role $demo $comp i.rbez, r

quietly eststo d:  reg sv_cand affair_cont $listdum , r
quietly eststo e:  reg sv_cand affair_cont $listdum $list $role $demo $comp , r
quietly eststo f:  reg sv_cand affair_cont $listdum $list $role $demo $comp i.rbez, r

esttab a c d f b e, compress b(2) se(2) star(* 0.05) label order(*affair*) drop(1.rbez)  /// 
rename(affair_cont affair) /// 
title(Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Regression Solution - Display of All Coefficients of Table 3 and Additional Models) ///
note("Note: Regression with robust standard errors on 2013 second vote shares of CSU candidates within their respective party list. Treatment indicator with binary (Models 1, 2, 5) or continuous specification (Models 3, 4, 6). Controls, as indicated, include dummies for first, second and third list position, absolute list position, length of list, dummies for candidates being member of local interest committee, cabinet member, regional party leader, leading party functionary, CSU frontrunner, district incumbent, being district candidate, having academic titles, being female, being incumbent since 2000, the number of legislative periods, age in years as well as dummies for the seven OLPR ballots (electoral districts) of Bavaria.") ///
mtitles("binary treat." "binary treat." "cont. treat." "cont. treat." "binary treat." "cont. treat.") ///
collabels("Vote share" ,lhs(Dep. var.: Within CSU list vote))


*********************************************
*Table A8: Impact of Affair on Vote Shares of Candidates within CSU Party Lists - CEM Matching Solution 
*********************************************

use tables\candidates_csu_replication.dta, clear
keep if year==2013

global agecut = " cand_age(20 30 45 60 80)"

eststo clear
**
*Model 5: very detailed matching, large imbalance reduction, no common support for many treatment/control observations

cem list_pre(1.5 2.5 3.5 6.5 10.5) listN_cand gov2 frontrunner bezirksvorsitz01 parteiamt local_committee title $agecut gender leg(0 1 2 3 4) incumb_2000 district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
eststo a: reg sv_cand affair [iweight=cem_weights]

*scalars
quietly imb list_pre listN_cand gov2 frontrunner bezirksvorsitz01 parteiamt local_committee title cand_age gender leg incumb_2000 district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): a
quietly cem list_pre(1.5 2.5 3.5 6.5 10.5) listN_cand gov2 frontrunner bezirksvorsitz01 parteiamt local_committee title $agecut gender leg(0 1 2 3 4) incumb_2000 district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar cemL1 = r(L1): a
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': a
estadd scalar controls = `a0': a
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): a

**
*Model 1,6: matching on fewer controls, esp. not OLPR list length, local interest comitee, incumbent since 2000 

cem list_pre(1.5 2.5 3.5 6.5 10.5) gov2 frontrunner bezirksvorsitz01 parteiamt title $agecut gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
eststo b: reg sv_cand affair [iweight=cem_weights]
eststo c: reg sv_cand affair list_pre gov2 frontrunner bezirksvorsitz01 parteiamt title cand_age gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 [iweight=cem_weights]

*scalars
quietly imb list_pre gov2 frontrunner bezirksvorsitz01 parteiamt title cand_age gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): b c
quietly cem list_pre(1.5 2.5 3.5 6.5 10.5) gov2 frontrunner bezirksvorsitz01 parteiamt title $agecut gender district_candidate rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar cemL1 = r(L1): b c
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': b c
estadd scalar controls = `a0': b c
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): b c

**
*Model 2,7: matching on fewer controls, esp. not OLPR list length, local interest comitee, incumbent since 2000 & for district candidate, frontrunner, local party leader, party functionary,  list position coarsening reduced to (1 2 3-10 else)

cem list_pre(1.5 2.5 10.5) gov2 title $agecut gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
eststo d: reg sv_cand affair [iweight=cem_weights]
eststo e: reg sv_cand affair list_pre gov2 title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 [iweight=cem_weights]

*scalars
quietly imb list_pre gov2 title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): d e
quietly cem list_pre(1.5 2.5 10.5) gov2 title $agecut gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar cemL1 = r(L1): d e
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': d e
estadd scalar controls = `a0': d e
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): d e

**
*Model 3, 8: matching on fewer controls (comp Mod. 3, add. list position coarsening reduced to (1 2 else))

cem list_pre(1.5 2.5) gov2 title gender $agecut rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7  , treatment(affair)
eststo f: reg sv_cand affair [iweight=cem_weights]
eststo g: reg sv_cand affair list_pre title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 [iweight=cem_weights]

*scalars
quietly imb list_pre gov2 title cand_age gender rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7 , treatment(affair)
estadd scalar imbL1 = r(L1): f g
quietly cem list_pre(1.5 2.5) gov2 title gender $agecut rbez_d1 rbez_d2 rbez_d3 rbez_d4 rbez_d5 rbez_d6 rbez_d7  , treatment(affair)
estadd scalar cemL1 = r(L1): f g
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': f g
estadd scalar controls = `a0': f g
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): f g


**
*Model 4, 9: matching only on pre-electoral list position, coarsened to 1 2 3-6 7-10 else)

cem list_pre(1.5 2.5 3.5 6.5 10.5)  , treatment(affair)

eststo h: reg sv_cand affair [iweight=cem_weights]
eststo i: reg sv_cand affair list_f list_s list_t list_pre  [iweight=cem_weights]

*scalars
quietly imb list_pre gov2  , treatment(affair)
estadd scalar imbL1 = r(L1): h i
quietly cem list_pre(1.5 2.5 3.5 6.5 10.5) , treatment(affair)
estadd scalar cemL1 = r(L1): h i
matrix b = r(match_table)
local a0 = b[2,1]
local a1 = b[2,2]
estadd scalar treat = `a1': h i
estadd scalar controls = `a0': h i
quietly sum sv_cand [aweight=cem_weights] if affair==0
estadd scalar control_mean = r(mean): h i


**
*Table

esttab c e g i a b d f h, compress label b(2) se(2) star(* 0.05) stats(N treat controls imbL1 cemL1 control_mean, fmt(a3 a3) labels(N "Matched treated" "Matched controls" "Pre-Matching L1 Imbalance" "Post-Matching L1 Imbalance")) ///
order(affair list_? list_pre cand_age *gov2 *rbez*) keep(affair list_? list_pre cand_age *gov2 *rbez* ) ///
title({\b Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - CEM Matching Solution - Display of All Coefficients of Table 4 and Additional Models}) ///
note("Note: Average treatment effect on the treated for second vote shares within CSU regional lists for running affair candidates with weights obtained by coarsened exact matching (standard errors in parentheses). Control variables, as indicated, adjust for remaining imbalance (L1 statistic) in the sample and improve efficiency. Model 1-4 show Models 1-4 of Table 4 in the main text with all control variable coefficients. Model 5 reports results on a matching solution drawing on all control variables as included in Table 3 of the main text. Models 6-9 correspond to Models 1-4, but estimate the ATT without inclusion of control variables. For Model 1, candidates are matched by ballot position (coarsened to 1, 2, 3, 4-6, 7-10, else), dummies for government function, being frontrunner, regional party leader, party functionary, academic title, gender, being SMD candidate, dummies for the seven regional ballots and age (coarsened to 20-29, 30-44, 45-59, 60-80). For Model 2, candidates are matched by ballot position (coarsened to 1, 2, 3-10, else), dummies for government function, title, gender, regional ballot dummies and age (coarsened to 20-29, 30-44, 45-59, 60-80). Model 3 differs to Model 2 by coarsening ballot position broader, only by 1, 2, else. Model 4 only matches by ballot position (coarsened to 1, 2, 3, 4-6, 7-10, else).") ///
collabels("binary treat.",lhs(Dep. var.: CSU vote shares)) 

*********************************************
*Table A11: Robustness of Table 3 - Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Papke-Wooldridge Approach for Proportions 
*********************************************
eststo clear

eststo: glm sv_cand_prop affair $listdum  , fam(binomial) link(logit) rob
eststo: glm sv_cand_prop affair $listdum $list $role $demo $comp i.rbez , fam(binomial) link(logit) rob
eststo: glm sv_cand_prop affair_cont $listdum  , fam(binomial) link(logit) rob
eststo: glm sv_cand_prop affair_cont $listdum $list $role $demo $comp i.rbez , fam(binomial) link(logit) rob

esttab , compress b(2) se(2) star(* 0.05) label order(*affair*) drop(1.rbez) /// 
rename(affair_cont affair) /// 
title({\b Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Papke-Wooldridge Approach for Proportions/Nonlinear Modelling with Logged Dependent Variable}) ///
note("Logistic regression following Papke and Wooldridge (1996) with robust standard errors on 2013 proportion of second votes of CSU candidates within their respective party list. Treatment indicator with binary or continouus specification (as indicated). Controls include dummies for first, second and third list position, absolute list position, length of list, dummies for candidates being member of local interest committee, cabinet member, regional party leader, leading party functionary, CSU frontrunner, district incumbent, being district candidate, academic titles, females, being incumbent since 2000, the number of legislative periods, age in years as well as dummies for the seven OLPR ballots (electoral districts) of Bavaria.") ///
collabels("M1/2:binary;M3/4:cont treat.",lhs(Dep. var.: Within CSU list vote proportion))


*********************************************
*Table A12: Robustness of Table 3 - Impact of Affair on Ranking of Candidates within CSU Party Lists
*********************************************

use tables\candidates_csu_replication.dta, clear
keep if year==2013

global listdum = "list_f list_s list_t" 
global list = "list_pre listN_cand"
global role = "gov2 frontrunner bezirksvorsitz01 parteiamt local_committee"
global demo = "title cand_age gender" 
global comp = "i.leg incumb_2000 nachruecker incumbency_stk  district_candidate" 

eststo clear

eststo:  reg list_diff affair $listdum $list $role $demo $comp `r'
eststo:  reg list_diff affair $listdum $list $role $demo $comp i.rbez `r'
eststo:  reg list_diff affair_cont $listdum $list $role $demo $comp `r'
eststo:  reg list_diff affair_cont $listdum $list $role $demo $comp i.rbez `r'

esttab , compress b(2) se(2) star(* 0.05) label order(*affair*) drop(1.rbez) /// 
rename(affair_cont affair) /// 
title({\b Table : Impact of Affair on Ranking of Candidates within CSU Party Lists - Full Specification}) ///
note("Note: Regression with robust standard errors on 2013 difference in pre-electoral ballot positions and post-electoral ranking of CSU candidates within their respective party list. Treatment indicator with binary (Models 1-2) or continuous specification (Models 3-4). Controls include dummies for first, second and third list position, absolute list position, length of list, dummies for candidates being member of local interest committee, cabinet member, regional party leader, leading party functionary, CSU frontrunner, district incumbent, being district candidate, academic titles, females, being incumbent since 2000, the number of legislative periods, age in years as well as dummies for the seven OLPR ballots (electoral districts) of Bavaria.") ///
mtitles("binary treat." "binary treat." "cont. treat." "cont. treat.") ///
collabels("Diff. in ranking",lhs(Dep. var.: Within CSU list position))


*********************************************
*Table A13: Robustness of Table 3 - Impact of Affair on 2008-2013 Difference in Vote Shares of Candidates within CSU Party Lists
*********************************************

use tables\candidates_csu_replication.dta, clear

keep if rerunning == 1 

xtset id year, delta(5)
fvset base 2008 year 
fvset base 0 leg
fvset base 0 incumbency_stk
fvset base 1 incumbency_stk

global listdum = "list_f list_s list_t " 
global list = "list_pre" // list_pre (no cue for unobserved quality with DiD design)
global comp = " incumbency_stk  i.leg nachruecker district_candidate" // incumb_2000 (omitted [constant]) incumbency_list [coll] 
global role = "gov2  bezirksvorsitz01 parteiamt local_committee" // frontrunner (not rerunning)
global demo = " retirement young " // title gender (omitted [constant]) age(constant, recoded to relevant cagtegories)

eststo clear

quietly eststo:  xtreg sv_cand affair $listdum $list $comp $demo i.year , fe cluster(id)
quietly eststo:  xtreg sv_cand affair $listdum $list $comp $role $demo i.year , fe cluster(id)
quietly eststo:  xtreg sv_cand affair $listdum $list $comp $role $demo i.year##i.rbez  , fe cluster(id)
quietly eststo:  xtreg sv_cand affair_cont $listdum $list $comp $demo i.year , fe cluster(id)
quietly eststo:  xtreg sv_cand affair_cont $listdum $list $comp $role $demo i.year , fe cluster(id)
quietly eststo:  xtreg sv_cand affair_cont $listdum $list $comp $role $demo i.year##i.rbez  , fe cluster(id)

esttab , compress b(2) se(2) star(* 0.05) label ///
drop(2008.* 2013.year#1.rbez ?.rbez) order(*affair* $listdum $list incumbency_stk *leg* nachruecker $role $demo *year* ) /// 
rename(affair_cont affair) /// 
title(Table A13: Impact of Affair on 2008-2013 Difference in Vote Shares of Candidates within CSU Party Lists) ///
note("Note: Fixed effects regression with standard errors cluster by candidate of 2008-2013 second vote shares of CSU candidates within their respective party list. Sample draws on all candidates running both in 2008 and 2013. Treatment indicator with binary (Models 1-3) or continuous specification (Models 4-6). Controls, as indicated, include dummies for first, second and third list position, dummies for candidates being member of local interest committee, cabinet member, regional party leader, leading party functionary, district incumbent, dummies for the number of legislative periods (1-4), having reached retirement age/being below 35 years and allowing for different trends in the seven OLPR ballots (electoral districts) of Bavaria.") ///
mtitles("binary treat." "binary treat." "binary treat." "binary treat." "cont. treat." "cont. treat." "cont. treat." "cont. treat.") ///
collabels("Vote share",lhs(Dep. var.: Within CSU list vote))


*********************************************
*Table A14: Robustness of Table 3 � Leave-one-out Analysis for Coefficient of Affair Implication on Model 1 and 2 of Tables 3 and Model 2 and 4 of Tables A10 and A11 
*********************************************

use tables\candidates_csu_replication.dta, clear
keep if year==2013

global listdum = "list_f list_s list_t " 
global list = "list_pre listN_cand"
global role = "gov2 frontrunner bezirksvorsitz01 parteiamt local_committee"
global demo = "title cand_age gender" 
global comp = "i.leg incumb_2000 nachruecker incumbency_stk  district_candidate" 

eststo clear

***********
*Leave one out analysis

foreach s in "affair" "affair_cont" {
foreach t in sv_cand list_diff {
foreach x in `s' {
foreach y in `t' {
foreach v in 19 28 40 86 99  111 115 119 120 121 138 139 153 161 {
quietly eststo without`v': quietly reg `y' `x' $listdum $list $role $demo $comp i.rbez if year==2013 & id!=`v', r
}
quietly eststo with_all: quietly reg `y' `x' $listdum $list $role $demo $comp i.rbez if year==2013 , r
}
}

quietly esttab, se nostar keep(`s') // thanks to Ben Jann: http://www.stata.com/statalist/archive/2009-01/msg01084.html
matrix C = r(coefs)
eststo clear
local rnames : rownames C
local models : coleq C
local models : list uniq models
local i 0
foreach name of local rnames {
    local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
        local ++j
        matrix tmp = C[`i', 2*`j'-1]
        if tmp[1,1]<. {
            matrix colnames tmp = `model'
            matrix b = nullmat(b), tmp
            matrix tmp[1,1] = C[`i', 2*`j']
            matrix se = nullmat(se), tmp
        }
    }
    ereturn post b
    quietly estadd matrix se
    eststo `name'
}

**
*Models 1, 2, 4, 5 of Table A14
esttab , compress b(2) se(2) star(* 0.05)   ///
title({\b Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Leave-one-out analysis on Model 2 of Table X} - Depvar `t', treat `s') ///
note("Note: Regression with robust standard errors on 2013 `t' of CSU candidates within their respective party list. The treatment indicator is `s'. The reported coefficients are treatment effects, each estimated from a different regression as indicated in the heading, dropping the candidate named in the respective row from the analysis.") ///
collabels("Vote share" ,lhs(Dep. var.: `t'))
}
}

foreach s in "affair" "affair_cont" {
foreach z in `s' {
foreach v in 19 28 40 86 99  111 115 119 120 121 138 139 153 161 {
quietly eststo without`v': glm sv_cand_prop `z' $listdum $list $role $demo $comp i.rbez if year==2013 & id!=`v', fam(binomial) link(logit) rob
}
quietly eststo with_all: glm sv_cand_prop `z' $listdum $list $role $demo $comp i.rbez if year==2013, fam(binomial) link(logit) rob
}


quietly esttab, se nostar keep(`s') // thanks to Ben Jann: http://www.stata.com/statalist/archive/2009-01/msg01084.html
matrix C = r(coefs)
eststo clear
local rnames : rownames C
local models : coleq C
local models : list uniq models
local i 0
foreach name of local rnames {
    local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
        local ++j
        matrix tmp = C[`i', 2*`j'-1]
        if tmp[1,1]<. {
            matrix colnames tmp = `model'
            matrix b = nullmat(b), tmp
            matrix tmp[1,1] = C[`i', 2*`j']
            matrix se = nullmat(se), tmp
        }
    }
    ereturn post b
    quietly estadd matrix se
    eststo `name'
}

*Models 3, 6 of Table A14
esttab , compress b(2) se(2) star(* 0.05)   ///
title({\b Table : Impact of Affair on Vote Shares of Candidates within CSU Party Lists - Leave-one-out analysis on Model 2 of Table X} - Depvar sv_cand_prop, treat `s') ///
note("Note: Logistic regression with robust standard errors on 2013 difference in proportion of second votes of CSU candidates within their respective party list.") ///
collabels("Vote share" ,lhs(Dep. var.: sv_cand_prop))
}


*********************************************
*END
*********************************************

log close


